﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JOATServer.SocietyFramework.Core;

namespace JOATServer
{
    public class UIManagerAutomaton : Automaton
    {
        protected static readonly string IDLE_STATE = "IDLE_STATE";
        protected static readonly string DISPLAY_STATE = "DISPLAY_STATE";

        public UIManagerAutomaton()
        {
            currentStateName = IDLE_STATE;

            states.Add(IDLE_STATE, new IdleState(this));
            states[IDLE_STATE].transition = new SimpleTransition(this, DISPLAY_STATE);

            states.Add(DISPLAY_STATE, new DisplayState(this));
            states[DISPLAY_STATE].transition = new SimpleTransition(this, IDLE_STATE);
        }

        protected class IdleState : State
        {
            public IdleState(BaseAutomaton owner) : base(owner) { }

            public override void StateCode()
            {
                Owner.GetNextMessage();
            }
        }

        protected class DisplayState : State
        {
            public DisplayState(BaseAutomaton owner) : base(owner) { }

            public override void StateCode()
            {
                if (Owner.currentMessage != null)
                {
                    Console.WriteLine("{0} : {1}", Owner.currentMessage.From, Owner.currentMessage.Data);
                }
            }
        }
    }
}
